package com.hsmw.api.controller.user;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hsmw.api.service.HsmwLeasingCompanyService;
import com.hsmw.api.service.HsmwTpspUserService;
import com.hsmw.common.base.BasePage;
import com.htn.common.core.base.DataResponse;
import com.htn.common.core.utils.StringUtils;
import com.hsmw.domain.HsmwLeasingCompany;
import com.hsmw.domain.HsmwRole;
import com.hsmw.domain.HsmwTpspUser;
import com.hsmw.domain.HsmwUser;
import com.hsmw.domain.form.GetObjectByIdForm;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.hsmw.common.base.BaseController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 供应商用户表 前端控制器
 * </p>
 *
 * @author wd
 * @since 2021-10-26
 */
@RestController
@RequestMapping("/api/tpsp/user")
public class HsmwTpspUserController extends BaseController<HsmwTpspUserService, HsmwTpspUser> {


    @Autowired
    HsmwTpspUserService  hsmwTpspUserService;

    @Autowired
    private HsmwLeasingCompanyService hsmwLeasingCompanyService;

    /**
     * 获取用户的分页列表
	 *
     * @param basePage
	 * @return
     * */
    @ApiOperation(value = "获取供应商用户的分页列表", notes = "获取用户的分页列表", produces = "application/json")
    @PostMapping("/getTpspUserPage")
    public DataResponse getHsmwUserPage(@RequestBody @Valid BasePage<HsmwTpspUser> basePage) {
        IPage page = new Page(basePage.getPageNo(), basePage.getPageSize());
        HsmwTpspUser hsmwUser = basePage.getRequestData();
        if(StringUtils.isNull(hsmwUser)){
            hsmwUser = new HsmwTpspUser();
        }
        IPage<HsmwTpspUser> data = hsmwTpspUserService.getHsmwUserPage(page, hsmwUser);
        return new DataResponse(data);
    }


    /**
     * 获取租赁公司下拉列表
     */
    @ApiOperation(value = "负责公司 下拉列表", notes = "负责公司 下拉列表", produces = "application/json")
    @PostMapping("/getLeasingCompanySelect")
    public DataResponse getLeasingCompanySelect() {
        List<HsmwLeasingCompany> data = hsmwLeasingCompanyService.getLeasingCompanySelect();
        return new DataResponse(data);
    }
    /**
     * 根据ID查询数据
     *
     * @return
     */
    @ApiOperation(value = "根据id查询供应商用户数据", notes = "根据id查询数据", produces = "application/json")
    @PostMapping("/getTpspUserById")
    public DataResponse getHsmwUserById(@RequestBody GetObjectByIdForm form) {
        HsmwUser hsmwUser = hsmwTpspUserService.getTpspDetailById(form.getKey(),form.getType());
        return new DataResponse(hsmwUser);
    }

    /**
     * 新增
     * 修改  必须带ID
     * 删除  逻辑删除 修改FLAG
     * 启用/禁用 修改ENABLED
     *
     * @param hsmwUser
     * @return
     */
    @ApiOperation(value = "新增/修改/逻辑启用-禁用 供应商用户 接口", notes = "修改：传id；删除：传id+flag；启用/禁用：传enabled", produces = "application/json")
    @PostMapping("/saveOrUpdateTPspUser")
    public DataResponse saveOrUpdateHsmwUser(@RequestBody HsmwTpspUser hsmwUser) {
        return hsmwTpspUserService.saveOrUpdateHsmwUser(hsmwUser);
    }

}

